package com.fanhao.dllo.soundfm.fragment.Infofragmnet;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.fanhao.dllo.soundfm.R;
import com.fanhao.dllo.soundfm.adapter.CoolAdapter;
import com.fanhao.dllo.soundfm.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/11.
 * 听精彩
 */
public class CoolFragment extends BaseFragment {
    private TabLayout coolTabLayout;
    private ViewPager coolViewPager;
    private CoolAdapter coolAdapter;
    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected int getLayoutView() {
        return R.layout.fragment_cool;
    }

    @Override
    protected void initView() {
        coolTabLayout = findView(R.id.tabLayout_main);
        coolViewPager = findView(R.id.viewPager_main);
        coolViewPager.setOffscreenPageLimit(2);
        // 添加Fragment
        fragmentList.add(new RecommendFragment());
        fragmentList.add(new AnchorFragment());
        fragmentList.add(new RadioStationFragment());

        coolAdapter = new CoolAdapter(getActivity().getSupportFragmentManager(),
                getActivity(), fragmentList);
        coolViewPager.setAdapter(coolAdapter);

        // 设置Tablayout滑动条的颜色
        coolTabLayout.setSelectedTabIndicatorColor(0xFFDBB76C);
        coolTabLayout.setupWithViewPager(coolViewPager);
    }

    @Override
    protected void initData() {
        for (int i = 0; i < coolTabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = coolTabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(coolAdapter.getTabView(i));
            }

        }
    }
}
